package com.itheima.common.exception;

import com.itheima.common.result.Code;
import com.itheima.common.result.JsonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author zhengbinghua
 * @since 2022/10/13 19:28
 */
@RestControllerAdvice
public class MyExceptionAdvice {

    @ExceptionHandler(MyException.class)
    public JsonResult doMyException(MyException ex) {
        return new JsonResult(Code.ERROR, ex.getMessage(), null);
    }

    @ExceptionHandler(Exception.class)
    public JsonResult doException(Exception ex) {
        return new JsonResult(Code.SYSTEM_ERROR, ex.getMessage(), null);
    }
}
